#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 100005

struct Employee
{
    int brother, son;
} employee[maxn];
struct Temp {               //离散化前初始数据。
    int id;
    int ability;
}temp[maxn];
int n;
int BIT[maxn],order[maxn];
int ans[maxn];

bool cmp(Temp a,Temp b)
{
    return a.ability<b.ability;
}
void add(int i,int x)
{
    while(i<=n)
    {
        BIT[i]+=x;
        i+=i&-i;
    }
}
int sum(int i)
{
    int s=0;
    while(i>0)
    {
        s+=BIT[i];
        i-=i&-i;
    }
    return s;
}
void dfs(int u)
{
    //ans[u] -= sum(u);
    //add(u,1);
//	cout<<u<<":"<<ability[u]<<endl;
    add(ord[u], 1);
    ans[u] -= (sum(n)-sum(order[u]));

    for(int v=employee[u].son; v!=0; v=employee[v].brother)
    {
        dfs(v);
    }
    ans[u] += (sum(n)-sum(order[u]));
    //ans[u] += su
}
int main() {
    cin>>n;
    for(int i=1; i<=n; i++)
    {
//		cout<<i<<":";
        cin>>temp[i].ability;
        temp[i].id=i;
    }
    sort(temp+1,temp+n+1,cmp);
    for(int i=1; i<=n; i++)
    {
        order[temp[i].id]=i;			//请注意这里的离散化写法。 
        //ability[id[i]]=i;
        //cout<<i<<":"<<dzx[i].ability<<endl;

    }

    for(int i=2; i<=n; i++)
    {
        int p;
        cin>>p;
        employee[i].brother=employee[p].son;
        employee[p].son=i;
    }

    dfs(1);

    for(int i=1; i<=n; i++) cout<<ans[i]<<endl;

    return 0;
}